<?php

namespace JsonLowCode\UI;

use JsonLowCode\Schema;
use JsonLowCode\Traits\Props\HasClearable;
use JsonLowCode\Traits\Props\HasColor;
use JsonLowCode\Traits\Props\HasCount;
use JsonLowCode\Traits\Props\HasDefaultValue;
use JsonLowCode\Traits\Props\HasReadonly;
use JsonLowCode\Traits\Props\HasSize;
use JsonLowCode\UI\Traits\HasModel;

/**
 * Rate评分组件
 * @method static Rate make(string|int $value = null,  bool $isJSExpression = true) Rate组件
 */
class Rate extends Schema
{
    protected string $componentName = "NRate";

    use HasReadonly, HasColor, HasClearable, HasSize, HasDefaultValue, HasCount, HasModel;

    /**
     * @param string|int|null $value
     */
    public function __construct(string|int $value = null)
    {
        parent::__construct();
        !is_null($value)&&$this->bindModel('value', $value);
    }

    /**
     * 允许只激活一半图标
     * @param bool|string $bool
     * @return $this
     */
    public function allowHalf(bool|string $bool = true): static
    {
        return $this->prop('allowHalf', $bool);
    }

    /**
     * 清除当前值的回调
     * @param string $event () => {}
     * @return $this
     */
    public function onClear(string $event = "() => {}"): static
    {
        return $this->events('onClear', $event);
    }


    /**
     * 发生变化时触发的回调方法
     * @param string $event (value: number) => void
     * @return $this
     */
    public function onUpdateValue(string $event = "(value) => {}"): static
    {
        return $this->events('onUpdate:value', $event);
    }


}
